package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.IMemberDao;
import com.itheima.dao.IOrderDao;
import com.itheima.service.IMemberService;
import com.itheima.service.IReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = IReportService.class)
@Transactional
public class ReportServiceImpl implements IReportService {

    @Autowired
    private IMemberDao memberDao;

    @Autowired
    private IOrderDao orderDao;

    /**
     * 运营数据统计
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {

        // 当前日期
        String reportDate = DateUtils.parseDate2String(DateUtils.getToday());
        // 本周星期一
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        // 本月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        // 当天新增会员
        Integer todayNewMember = memberDao.findCountByDate(reportDate);
        // 总会员数
        Integer totalMember = memberDao.findTotolCountByDate();
        // 本周新增会员数
        Integer thisWeekNewMember = memberDao.findCountByMonday(thisWeekMonday);
        // 本月新增会员数
        Integer thisMonthNewMember = memberDao.findCountByMonth(firstDay4ThisMonth);

        // 当天预约人数
        Integer todayOrderNumber = orderDao.findCountByDate(reportDate);
        // 当天到诊人数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDaTe(reportDate);
        // 本周预约人数
        Integer thisWeekOrderNumber = orderDao.findCountByMonday(thisWeekMonday);
        // 本周到诊人数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountByMonday(thisWeekMonday);
        // 本月预约人数
        Integer thisMonthOrderNumber = orderDao.findCountByMonth(firstDay4ThisMonth);
        // 本月到诊人数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountByMonth(firstDay4ThisMonth);

        // 热门套餐
        List<Map<String,Object>> hotSetmeal = orderDao.findHotSetmeal();

        Map<String,Object> data = new HashMap<String,Object>();

        data.put("reportDate",reportDate);

        data.put("todayNewMember",todayNewMember);
        data.put("totalMember",totalMember);
        data.put("thisWeekNewMember",thisWeekNewMember);
        data.put("thisMonthNewMember",thisMonthNewMember);

        data.put("todayOrderNumber",todayOrderNumber);
        data.put("todayVisitsNumber",todayVisitsNumber);
        data.put("thisWeekOrderNumber",thisWeekOrderNumber);
        data.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        data.put("thisMonthOrderNumber",thisMonthOrderNumber);
        data.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        data.put("hotSetmeal",hotSetmeal);

        return data ;
    }
}
